#ifndef _BITMAP_H_
#define	_BITMAP_H_

#include <Types.h>

namespace Utils
{
	class Bitmap
	{
	public:
		Bitmap();
		Bitmap(uint64_t size);
		Bitmap(uintptr_t pos, uint64_t size);
		
		void Init(uintptr_t pos, uint64_t size, bool reset = true);
		
		void Set(uint64_t index);
		void Clear(uint64_t index);
		bool Test(uint64_t index) const;
		
		void Massive(uint64_t first, uint64_t count, bool value);
		
		uint64_t FindFirst(uint64_t base, bool Value = false) const;
		
	protected:
		void Reset();
		
		uint64_t GetFirstIndex(uint64_t FirstPage, bool Value) const;
		uint64_t GetFirstOffset(uint64_t index, uint64_t startOffset, bool Value) const;
		bool IndexContains(uint64_t index, bool Value) const;
		
		bool MassiveStage1(uint64_t &base, uint64_t &pages);
		bool MassiveStage2(uint64_t &base, uint64_t &pages);
		void MassiveStage3(uint64_t base, uint64_t pages);
		
		uint64_t *Data;
		uint64_t Size, SizeInEntries;
	};
}

#endif
